package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.RetreatApplyDto;
import com.zzyl.service.RetreatService;
import com.zzyl.vo.RetreatDetailVo;
import com.zzyl.vo.RetreatPageQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

/**
 * 退住相关接口
 *
 * @author itcast
 * @create 2023/12/20 16:23
 **/
@RestController
@RequestMapping("/retreat")
@Api(tags = "管理端 - 退住管理")
public class RetreatController {
    @Autowired
    private RetreatService retreatService;

    @PostMapping("/apply")
    @ApiOperation(value = "申请退住")
    public ResponseResult<Void> apply(@RequestBody RetreatApplyDto retreatApplyDto) {
        retreatService.apply(retreatApplyDto);
        return ResponseResult.success();
    }

    @ApiOperation(value = "分页查询")
    @GetMapping("/pageQuery")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "elderName", value = "老人姓名，模糊查询", required = false, dataTypeClass = String.class),
            @ApiImplicitParam(name = "elderIdCardNo", value = "身份证号，精确查询", required = false, dataTypeClass = String.class),
            @ApiImplicitParam(name = "retreatStartTime", value = "退住开始时间，格式：yyyy-MM-dd HH:mm:ss", required = false, dataTypeClass = LocalDateTime.class),
            @ApiImplicitParam(name = "retreatEndTime", value = "退住结束时间，格式：yyyy-MM-dd HH:mm:ss", required = false, dataTypeClass = LocalDateTime.class),
            @ApiImplicitParam(name = "pageNum", value = "页码", example = "1", required = true, dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "pageSize", value = "页面大小", example = "10", required = true, dataTypeClass = Integer.class)
    })
    public ResponseResult<PageResponse<RetreatPageQueryVo>> pageQuery(@RequestParam(value = "elderName", required = false) String elderName,
                                                                      @RequestParam(value = "elderIdCardNo", required = false) String elderIdCardNo,
                                                                      @RequestParam(value = "retreatStartTime", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime retreatStartTime,
                                                                      @RequestParam(value = "retreatEndTime", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime retreatEndTime,
                                                                      @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                                      @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        return ResponseResult.success(retreatService.pageQuery(elderName, elderIdCardNo, retreatStartTime, retreatEndTime, pageNum, pageSize));
    }

    @GetMapping("/detail/{id}")
    @ApiOperation(value = "查询退住详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "退住id", required = true, dataTypeClass = Long.class)
    })
    public ResponseResult<RetreatDetailVo> detail(@PathVariable("id") Long id) {
        return ResponseResult.success(retreatService.detail(id));
    }
}
